package com.noble.glamour.third.share.view;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.noble.glamour.R;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.library.view.base.BaseDialogFragment;

/**
 * 分享弹出框
 */
public class HeartSharePanel extends BaseDialogFragment implements View.OnClickListener {
    private View share_weixin, share_qq;
    private TextView tv_title;
    private OnShareClickListener shareListener;
    double heightRatio = 0;

    public HeartSharePanel() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        setContentView(R.layout.share_dialog);
        tv_title = (TextView) findViewById(R.id.tv_title);
        share_weixin = findViewById(R.id.share_weixin);
        share_qq = findViewById(R.id.share_qq);
        share_weixin.setOnClickListener(this);
        share_qq.setOnClickListener(this);
        heightRatio = getContentView().getHeight() / ModuleMgr.getAppMgr().getScreenHeight();
        setDialogSizeRatio(1, heightRatio);
        setCanceledOnTouchOutside(true);
        settWindowAnimations(R.style.AnimDownInDownOut);
        setGravity(Gravity.BOTTOM);
        if (onCreateView != null) {
            onCreateView.onCreateViewOk();
        }
        return getContentView();
    }

    /**
     * 创建UI后的回调事件
     */
    private OnCreateView onCreateView = null;

    public interface OnCreateView {
        void onCreateViewOk();
    }

    /**
     * 初始化完成调用
     *
     * @param onCreateView
     */
    public void setOnCreateView(OnCreateView onCreateView) {
        this.onCreateView = onCreateView;
    }

    /**
     * 设置tip标题
     *
     * @param txt
     */
    public HeartSharePanel setTitle(String txt) {
        tv_title.setText(txt);
        return this;
    }

    /**
     * 设置分享按钮回调
     */
    public HeartSharePanel setOnShareListener(OnShareClickListener listener) {
        shareListener = listener;
        return this;
    }

    public interface OnShareClickListener {
        void shareWeiXin();

        void shareQQRoom();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.share_weixin:
                //调用微信分享
                shareListener.shareWeiXin();
                break;

            case R.id.share_qq:
                //调用qq分享
                shareListener.shareQQRoom();
                break;

            default:
                break;
        }
    }
}
